package com.nwcl.ysx.service.impl;

import com.nwcl.common.utils.BeanUtil;
import com.nwcl.ysx.bo.RestaurantRoomSubscribeBO;
import com.nwcl.ysx.dao.RestaurantRoomSubscribeDao;
import com.nwcl.ysx.entity.RestaurantRoomSubscribe;
import com.nwcl.ysx.service.RestaurantRoomSubscribeService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @author liguiqin
 * @date 2023/5/26
 */
@Service
public class RestaurantRoomSubscribeImpl implements RestaurantRoomSubscribeService {
    @Autowired
    private RestaurantRoomSubscribeDao restaurantRoomSubscribeDao;

    @Override
    public List<RestaurantRoomSubscribeBO> listTimeRangeOverlapping(Integer restaurantId, Integer roomId, String startTime, String endTime) {
        List<RestaurantRoomSubscribe> modelList=  restaurantRoomSubscribeDao.listTimeRangeOverlapping(restaurantId, roomId, startTime, endTime);
        if(CollectionUtils.isEmpty(modelList)){
            return Collections.emptyList();
        }
        return BeanUtil.copyList(modelList,RestaurantRoomSubscribeBO.class);
    }

    @Override
    public void save(RestaurantRoomSubscribeBO roomSubscribeBO) {
        RestaurantRoomSubscribe subscribe=BeanUtil.copy(roomSubscribeBO,RestaurantRoomSubscribe.class);
        restaurantRoomSubscribeDao.save(subscribe);
    }

    @Override
    public RestaurantRoomSubscribeBO getBySubscribeId(Integer subscribeId) {
        RestaurantRoomSubscribe subscribe = restaurantRoomSubscribeDao.getBySubscribeId(subscribeId);
        if (subscribe != null) {
            return BeanUtil.copy(subscribe, RestaurantRoomSubscribeBO.class);
        }
        return null;
    }
}
